package com.smartjobs.loader;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.io.PrintStream;

import com.smartjobs.util.RuntimeSettings;



public class MergeFile {

    @SuppressWarnings("resource")
	public static void mergeFile(){  
        try {  
            File f1 = new File(RuntimeSettings.location+"\\header.txt");  
            File f2 = new File(RuntimeSettings.location+"\\schema.txt");  
            File f3 = new File(RuntimeSettings.location+"\\jobs.rdf");  
            File f4 = new File(RuntimeSettings.location+"\\smartJobs.rdf");
            File f5 = new File(RuntimeSettings.location+"\\MergedOntology.owl");
            FileInputStream fin1 = new FileInputStream(f1);  
            FileInputStream fin2 = new FileInputStream(f2);
            FileInputStream fin3 = new FileInputStream(f3);  
            FileInputStream fin4 = new FileInputStream(f4);  
  
            
            FileOutputStream fout = new FileOutputStream(f5);  
  
            BufferedReader br = new BufferedReader(new InputStreamReader(fin1));
            PrintStream ps = new PrintStream(fout);
            String s="";
            while((s=br.readLine())!=null)
            {
            	ps.println(s);
            	
            }
            ps.println("<!-- ##########Schema########### -->");
            
            br =  new BufferedReader(new InputStreamReader(fin2));
            while((s=br.readLine())!=null)
            {
            	ps.println(s);
            	
            }
            
            ps.println("<!-- ##########http:\\www.jobs.com########### -->");
            br =  new BufferedReader(new InputStreamReader(fin3));
            while((s=br.readLine())!=null)
            {
            	if(!(s.contains("xmlns")||s.contains("xml:base")||s.contains("rdf:RDF")||s.contains("<?xml version")))
                	ps.println(s);
            	
            }
            
            ps.println("<!-- ##########http:\\www.smartJobs.com########### -->");
            br =  new BufferedReader(new InputStreamReader(fin4));
            boolean flag=false;
            while((s=br.readLine())!=null)
            {
            	if(s.contains("<!-- Instances -->"))
            	{
            		flag=true;
            	}
            	
            	if(flag)
            	{	
            		if(!s.contains("</rdf:RDF>"))
            		{	
            			s=s.replace("vocab", "vocab2");
            			ps.println(s);
            		}	
            		
            	}	
            	
            }
            
            ps.println("</rdf:RDF>");
            
           
         
            fin2.close();  
            fout.close();  
        }  
        catch (Exception e){  
            System.out.println("Err (MergaFile) " + e.toString());  
        }  
    }  
	
//    public static void main(String[] args) {
//		new MergeFile().mergeFile();
//	}
    
}
